package com.ds.dsm.aggregation.config.api;

import com.ds.common.JDSException;
import com.ds.esd.custom.annotation.CustomAnnotation;
import com.ds.esd.custom.annotation.FieldAnnotation;
import com.ds.esd.custom.bean.enums.ModuleViewType;
import com.ds.esd.custom.grid.annotation.GridAnnotation;
import com.ds.esd.custom.grid.annotation.PageBar;
import com.ds.esd.custom.grid.enums.GridMenu;
import com.ds.esd.dsm.DSMFactory;
import com.ds.esd.dsm.temp.JavaTemp;
import com.ds.esd.dsm.view.field.FieldModuleConfig;

import java.util.Set;

@PageBar
@GridAnnotation(customMenu = {GridMenu.Reload})
public class AggAPIConfigView {
    @CustomAnnotation(hidden = true, pid = true)
    String viewInstId;

    @CustomAnnotation(hidden = true, pid = true)
    String domainId;

    @CustomAnnotation(caption = "视图名称")
    String viewName;

    @CustomAnnotation(caption = "视图类型")
    ModuleViewType viewType;

    @CustomAnnotation(caption = "方法名称", uid = true)
    String methodName;

    @FieldAnnotation( rowHeight = "150")
    @CustomAnnotation(caption = "类名", pid = true)
    String sourceClassName;

    @CustomAnnotation(caption = "访问地址")
    String url;

    @CustomAnnotation(caption = "使用模板")
    String javaTempName;


    public AggAPIConfigView() {

    }


    public AggAPIConfigView(FieldModuleConfig moduleConfig) {
        this.methodName = moduleConfig.getMethodName();
        this.viewInstId = moduleConfig.getViewInstId();
        this.domainId = moduleConfig.getDomainId();
        this.viewType = moduleConfig.getMethodConfig().getModuleViewType();
        this.url = moduleConfig.getUrl();
        this.viewName = moduleConfig.getCaption();
        try {
            Set<String> tempIds = moduleConfig.getMethodConfig().getJavaTempIds();
            if (tempIds.size() > 0) {
                JavaTemp temp = DSMFactory.getInstance().getTempManager().getJavaTempById(tempIds.iterator().next());
                this.javaTempName = temp.getName();
            }
            this.sourceClassName = moduleConfig.getSourceClassName();
        } catch (JDSException e) {
            e.printStackTrace();
        }
    }

    public String getDomainId() {
        return domainId;
    }

    public void setDomainId(String domainId) {
        this.domainId = domainId;
    }

    public String getViewName() {
        return viewName;
    }

    public void setViewName(String viewName) {
        this.viewName = viewName;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public ModuleViewType getViewType() {
        return viewType;
    }

    public void setViewType(ModuleViewType viewType) {
        this.viewType = viewType;
    }

    public String getJavaTempName() {
        return javaTempName;
    }

    public void setJavaTempName(String javaTempName) {
        this.javaTempName = javaTempName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getViewInstId() {
        return viewInstId;
    }

    public void setViewInstId(String viewInstId) {
        this.viewInstId = viewInstId;
    }

    public String getSourceClassName() {
        return sourceClassName;
    }

    public void setSourceClassName(String sourceClassName) {
        this.sourceClassName = sourceClassName;
    }
}
